#include <stdio.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
#define OK 1 
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
typedef int Status;
typedef int SElemType;
typedef struct
{
    SElemType * base;
    SElemType * top;
    int stacksize;
}SqStack;
// P47
Status InitStack(SqStack &S)
{
    S.base = (SElemType *)malloc(STACK_INIT_SIZE * sizeof(SElemType));
    if (!S.base) exit(ERROR);
    S.top = S.base;
    S.stacksize = STACK_INIT_SIZE;
    return OK;
}
Status GetTop(SqStack S, SElemType &e)
{
    if (S.top == S.base)
        return OVERFLOW;
    e = *(S.top - 1);
    return OK;
}
Status Push(SqStack &S, SElemType &e)
{
    if (S.top - S.base >= S.stacksize)
    {
        S.base = (SElemType *)realloc(S.base, (STACK_INIT_SIZE + STACKINCREMENT) * sizeof(SElemType));
        if (!S.base)
            return OVERFLOW;
        S.top = S.base + S.stacksize;
        S.stacksize += STACKINCREMENT;
    }
    *S.top++ = e;
    return OK;
}
Status Pop(SqStack &S, SElemType &e)
{
    if (S.top == S.base)
        return ERROR;
    e = *--S.top;
    return OK;
}
Status StackEmpty(SqStack S)
{
    if (S.top == S.base)
        return TRUE;
    else
        return FALSE;
}
// p48 algorithm 3.1
void conversion()
{

    SqStack S;
    InitStack(S);
    SElemType N;
    scanf("%d", &N);
    while (N)
    {
        SElemType e = N % 8;
        Push(S, e);
        N /= 8;
    }
    while (!StackEmpty(S))
    {
        SElemType e;
        Pop(S, e);
        printf("%d", e);
    }
}

int main(void)
{
    conversion();

    return 0;
}


